package com.football;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import model.Message;



public class AddMessageFrame extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static void main(String args[]){
		new AddMessageFrame();
	}
	public AddMessageFrame() {
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		Point p = new Point();
		p.x=100;
		p.y=100;
		this.setLocation(p);
		Dimension d = new Dimension();
		d.setSize(400, 400);
		this.setSize(d);
		Container con = this.getContentPane();
		JPanel panel = new JPanel();
		panel.setLayout(null);
		
		JLabel nameLabel = new JLabel("Your Name:");
		final JTextField name = new JTextField();
		nameLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
		Point p1 = new Point();
		p1.x=10;
		p1.y=10;
		nameLabel.setLocation(p1);
		Dimension d1 = new Dimension();
		d1.setSize(100, 30);
		nameLabel.setSize(d1);
		
		Point p2 = new Point();
		p1.x=120;
		p1.y=10;
		name.setLocation(p2);
		Dimension d2 = new Dimension();
		d2.setSize(200, 30);
		name.setSize(d2);

		panel.add(nameLabel);
		panel.add(name);
		JLabel addressLabel = new JLabel("Address:");
		final JTextField address = new JTextField();
		
		Point p3 = new Point();
		p3.x=10;
		p3.y=50;
		addressLabel.setLocation(p3);
		Dimension d3 = new Dimension();
		d2.setSize(100, 30);
		addressLabel.setSize(d2);
		addressLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
		
		Point p4 = new Point();
		p4.x=10;
		p4.y=50;
		address.setLocation(p4);
		Dimension d3 = new Dimension();
		d3.setSize(100, 30);
		address.setSize(d3);

		panel.add(addressLabel);
		panel.add(address);
		
		JLabel telLabel = new JLabel("Telephone:");
		telLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
		final JTextField tel = new JTextField();
		
		Point p5 = new Point();
		p5.x=10;
		p5.y=50;
		address.setLocation(p4);
		Dimension d3 = new Dimension();
		d3.setSize(100, 30);
		address.setSize(d3);
		telLabel.setBounds(10, 90, 100, 30);
		
		tel.setBounds(120, 90, 200, 30);
		panel.add(telLabel);
		panel.add(tel);
		
		JLabel emailLabel = new JLabel("Email:");
		emailLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
		final JTextField email = new JTextField();
		emailLabel.setBounds(10, 130, 100, 30);
		email.setBounds(120, 130, 200, 30);
		panel.add(emailLabel);
		panel.add(email);
		JLabel titleLabel = new JLabel("Title:");
		titleLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
		final JTextField title = new JTextField();
		
		titleLabel.setBounds(10, 170, 100, 30);
		title.setBounds(120, 170, 200, 30);
		panel.add(titleLabel);
		panel.add(title);
		JLabel contentLabel = new JLabel("Content:");
		contentLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
		final JTextField content = new JTextField();
		contentLabel.setBounds(10, 210, 100, 30);
		content.setBounds(120, 210, 200, 30);
		panel.add(contentLabel);
		panel.add(content);
		
		JButton confirm = new JButton("Submit");
		confirm.setBounds(10, 280, 100, 40);
		JButton Empty = new JButton("Empty");
		Empty.setBounds(130, 280, 100, 40);
		panel.add(confirm);
		panel.add(Empty);
		con.setLayout(new BorderLayout());
		con.add(panel, BorderLayout.CENTER);
		this.setVisible(true);
		
		confirm.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				
				String nameStr = name.getText();
				String addressStr = address.getText();
				String telStr = tel.getText();
				String emailStr = email.getText();
				String titleStr = title.getText();
				String contentStr = content.getText();
				
				Message msg = new Message();
				msg.setAddress(addressStr);
				msg.setcontents(contentStr);
				msg.setEmail(emailStr);
				msg.setusername(nameStr);
				msg.settelephone(telStr);
				msg.setTitle(titleStr);
//				messageList.add(msg); // 将发送的信息存储在list中
				JOptionPane.showMessageDialog(null, "Leave message successfully!");
			}

		});

		Empty.addActionListener(
				new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						
						name.setText("");
						email.setText("");
						address.setText("");
						tel.setText("");
						title.setText("");
						content.setText("");
						
					}
				}

		);
	}
}
